package edu.zcmu.seckill.controller;


import edu.zcmu.seckill.entity.SeckillProduct;
import edu.zcmu.seckill.response.R;
import edu.zcmu.seckill.service.SeckillProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 唐诗
 * @since 2022-02-22
 */
@Slf4j
@RestController
@RequestMapping("/seckill/seckill-product")
public class SeckillProductController {

    @Autowired
    SeckillProductService seckillProductService;

    /**
     * 获取当前正在秒杀的产品
     * @return
     */
    @GetMapping("/getNow")
    public R getNow(@RequestParam("pageNum") Integer pageNum){
      HashMap<String,Object> map=seckillProductService.getNow(pageNum);
        return R.ok().data(map);
    }

    /**
     * 获取预热中的产品
     * @param pageNum
     * @return
     */
    @GetMapping("/getBefore")
    public R getBefore(@RequestParam("pageNum") Integer pageNum){
        HashMap<String,Object> map=seckillProductService.getBefore(pageNum);
        return R.ok().data(map);
    }

    /**
     * 获取过期的产品
     * @param pageNum
     * @return
     */
    @GetMapping("/getAfter")
    public R getAfter(@RequestParam("pageNum") Integer pageNum){
        HashMap<String,Object> map=seckillProductService.getAfter(pageNum);
        return R.ok().data(map);
    }

    /**
     * 根据id获取秒杀产品信息
     * @param id
     * @return
     */
    @GetMapping("/getSeckillProductById/{id}")
    public R getSeckillProductById(@PathVariable Integer id){
        HashMap<String, Object> seckillProductById = seckillProductService.getSeckillProductById(id);
        return  R.ok().data(seckillProductById);
    }


}
